<template>
	<view>
		<view class="h100">
			<view class="info">
				<image src="/static/icons/team_number@2x.png" class="team_num"></image>
				<image src="/static/icons/team_profit@2x.png" class="team-profit"></image>
				<view class="team-num">
					<view class="title" v-if="showNext">
						一级人数
					</view>
					<view class="title" v-else>
						二级人数
					</view>
					<view class="num">
						{{count}}
					</view>
				</view>
				<view class="benefit">
					<view class="title">
						个人总收益
					</view>
					<view class="num">
						￥{{amount.toFixed(2)}}
					</view>
				</view>
			</view>
		</view>

		<view class="team-list">
			<view class="item" v-for="(item,index) in teamList" :key="index">
				<view class="left">
					<text class="name_profit">{{item.nickname}}（￥{{item.amount.toFixed(2)}}）</text>
				</view>
				<view class="right">
					<text class="phone">{{item.phone}}</text><text class="lower_level" v-if="showNext"
						@click="toNextLevel(item)">下级({{item.count}})</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				teamList: [], // 团队列表
				amount: 0, // 收益
				count: 0, // 人数
				showNext:true // 下级分销，默认显示一级，点击一级到二级
			};
		},
		onLoad(option) {
			this.getTeamList(option.id)
			if(option.id){
				this.showNext=false
			}
		},
		methods: {
			// 查看下级
			toNextLevel(item) {
				console.log(item._id)
				if (item.count > 0) {
					uni.navigateTo({
						url: '/subpkg/my-team/my-team?id='+
						item._id
					})
					// 动态修改导航标题
					uni.setNavigationBarTitle({
					    title: item.nickname+'的团队'
					});
				}
			},
			// 获取团队xinxi
			async getTeamList(id) {
				const {
					data: res
				} = await uni.$http.post('/user/getTeam', {
					userId: id ? id : this.userInfo._id
				})
				console.log(res)
				if (res.success == 0) {
					this.teamList = res.data.next
					this.amount = res.data.amount
					this.count = res.data.count
				}
			}

		},
		computed: {
			...mapState('m_user', ['userInfo'])
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
	}

	.h100 {
		height: 150rpx;
		border-radius: 0 0 100rpx 100rpx;
		background-color: #4b4a49;
		position: relative;

		.info {
			width: 702rpx;
			height: 206rpx;
			background: #FFFFFF;
			box-shadow: 0px 2rpx 18rpx 2rpx rgba(40, 40, 40, 0.09);
			border-radius: 12rpx;
			position: absolute;
			bottom: -120rpx;
			left: 50%;
			transform: translateX(-50%);
			display: flex;
			justify-content: space-between;
			align-items: center;

			.team_num,
			.team-profit {
				position: absolute;
			}

			.team_num {
				width: 128rpx;
				height: 74rpx;
				bottom: 0;
				left: 15rpx;
			}

			.team-profit {
				width: 118rpx;
				height: 74rpx;
				right: 216rpx;
				bottom: 0;
			}

			.team-num {
				border-right: 2rpx solid #EEEAEA;
			}

			.team-num,
			.benefit {
				text-align: center;
				flex: 1;

				.title {
					font-size: 32rpx;
					font-weight: bold;
					color: #333333;
				}

				.num {
					font-size: 38rpx;
					font-weight: bold;
					color: #D80E0E;
					margin-top: 35rpx;
				}
			}
		}
	}

	.team-list {
		width: 702rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		margin-top: 150rpx;
		margin-left: 24rpx;
		padding: 0 25rpx;
		box-sizing: border-box;

		.item {
			height: 110rpx;
			line-height: 110rpx;
			border-bottom: 1rpx solid #e8e8e8;
			display: flex;
			justify-content: space-between;

			&:last-child {
				border-bottom: none;
			}

			.left {
				flex: 1;
			}

			.right {
				flex: 1;
				text-align: right;
			}

			.name_profit {
				font-size: 32rpx;
				font-weight: bold;
				color: #222222;
			}

			.phone {
				font-size: 30rpx;
				font-weight: bold;
				color: #999999;
				margin-right: 15rpx;
			}

			.lower_level {
				font-size: 30rpx;
				font-weight: bold;
				text-decoration: underline;
				color: #D80E0E;
			}
		}
	}
</style>
